package com.booksystem.controller;

import com.booksystem.common.RestResult;
import com.booksystem.dto.CustomerServiceTicketAddDTO;
import com.booksystem.dto.CustomerServiceTicketQueryDTO;
import com.booksystem.dto.CustomerServiceTicketReplyDTO;
import com.booksystem.dto.CustomerServiceTicketUpdateStatusDTO;
import com.booksystem.entity.CustomerServiceTicketDO;
import com.booksystem.service.CustomerServiceTicketService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.validation.Valid;
import javax.validation.groups.Default;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *   客服工单 Controller
 * </p>
 * @author 段伟豪
 */
@Slf4j
@Api(tags = "客服工单管理")
@RestController
@RequestMapping("/customer-service-ticket")
public class CustomerServiceTicketController {

    @Autowired
    private CustomerServiceTicketService customerServiceTicketService;

    /**
     * 提交客服工单
     *
     * @param addDTO 工单添加参数
     * @return RestResult 结果
     */
    @PostMapping("/submit")
    @ApiOperation("提交客服工单")
    public RestResult<Boolean> submitTicket(@Valid @RequestBody CustomerServiceTicketAddDTO addDTO) {
        Boolean result = customerServiceTicketService.submitTicket(addDTO);
        return new RestResult<>("000000", "调用成功", result);
    }

    /**
     * 查询客服工单列表
     *
     * @param queryDTO 查询参数
     * @return RestResult 结果
     */
    @GetMapping("/list")
    @ApiOperation("查询客服工单列表")
    public RestResult<PageInfo<CustomerServiceTicketDO>> getTicketsList(@Validated({Default.class}) CustomerServiceTicketQueryDTO queryDTO) {
        PageInfo<CustomerServiceTicketDO> result = customerServiceTicketService.getTicketsList(queryDTO);
        return new RestResult<>("000000", "调用成功", result);
    }

    /**
     * 更新客服工单状态
     *
     * @param updateStatusDTO 更新状态参数
     * @return RestResult 结果
     */
    @PutMapping("/update-status")
    @ApiOperation("更新客服工单状态")
    public RestResult<Boolean> updateTicketStatus(@Valid @RequestBody CustomerServiceTicketUpdateStatusDTO updateStatusDTO) {
        Boolean result = customerServiceTicketService.updateTicketStatus(updateStatusDTO);
        return new RestResult<>("000000", "调用成功", result);
    }

    /**
     * 回复客服工单
     *
     * @param replyDTO 回复参数
     * @return RestResult 结果
     */
    @PutMapping("/reply")
    @ApiOperation("回复客服工单")
    public RestResult<Boolean> replyTicket(@Valid @RequestBody CustomerServiceTicketReplyDTO replyDTO) {
        Boolean result = customerServiceTicketService.replyTicket(replyDTO);
        return new RestResult<>("000000", "调用成功", result);
    }
}